package 函数式编程

/**
 * 偏函数的使用
 */
object PartialFunDemo02 {
  def main(args: Array[String]): Unit = {
    val list = List(1, 2, 3, 4, "abc")
    val partialFun = new PartialFunction[Any, Int] {
      override def isDefinedAt(x: Any): Boolean = x.isInstanceOf[Int]

      //为ture 执行apply
      override def apply(v1: Any): Int = {
        v1.asInstanceOf[Int] + 1
      }
    }

    /*如果是使用偏函数,不能使用map,要使用collect*/
    val value = list.collect(partialFun)
    println(value)
  }

}
